﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
namespace Game_Tank
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        private int j = 299;
        private int flags = 0;
        int k = 253;

        #region Hàm con (chua su dung)
        int i = 0;
        private int[,] map = new int[50, 70];
        public void LoadMap()
        {
            string _path = "D:\\map.txt";
            StreamReader reader = new StreamReader(_path);
            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 70; j++)
                {
                    int a = reader.Read();
                    map[i, j] = a;
                }
            }
            reader.Close();
        }

        public void DrawMap(frmMain frm)
        {
            GraphicsPath grap = new GraphicsPath();
            Graphics gra = frm.CreateGraphics();
            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 70; j++)
                {
                    if (map[i, j] == 49)
                        grap.AddRectangle(new Rectangle(j * 10, i * 10, 10, 10));
                }
            }
            //Brush brush = new Brus
            gra.FillPath(Brushes.White, grap);
        }

        public void LoadTitile()
        {
 
        }
        #endregion

        #region Ham su dung trong menu

        public void NewGame(){}
        public void Option(){}
        public void HighScores(){}
        public void Credits(){}
        public void Exit(){}
        #endregion

        

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            LoadMap();
            //DrawMap(this);
        }

        
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (j > 50)
                this.pictureBox1.Location = new System.Drawing.Point(144, j = j - 5);
            else
                label1.Visible = label2.Visible = label3.Visible = label4.Visible = label5.Visible = pictureBox2.Visible = true;
                
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

            if (flags == 0)// flags = 0 man hinh menu
            {
                if (e.KeyCode == Keys.Down)
                    if (k < 413)
                        k = k + 40;
                    else k = 253;
                if (e.KeyCode == Keys.Up)
                    if (k > 253)
                        k = k - 40;
                    else k = 413;
                this.pictureBox2.Location = new System.Drawing.Point(238, k);
                if (e.KeyCode == Keys.Enter)
                {
                    switch (k)
                    {
                        case 253: flags = 1;// flags = 1 bat dau choi
                            NewGame();
                            break;
                        case 293: flags = 2; //flags = 2 option
                            Option();
                            break;
                        case 333: flags = 3; //flags = 3 highscores
                            HighScores();
                            break;
                        case 373: flags = 4; //flags = 4 credits
                            Credits();
                            break;
                        case 413: flags = 5; //flags = 5 exit
                            Application.Exit();
                            break;
                    }

                }
            }
            this.Refresh();
        }

        
    }
}
